import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: '',
    isLogin: false,
    searchHistory: []
  },
  mutations: {
    setUserInfo (state, userInfo) {
      state.userInfo = userInfo
    },
    setUserLogin (state, value) {
      state.isLogin = value
    },
    addSearchHistory (state, data) {
      // if (state.searchHistory.includes(data)) {
      //   // const _index = state.searchHistory.findIndex(data)
      //   // state.searchHistory.splice(_index, 1)
      //   // state.searchHistory.unshift(data)
      // } else {
      //   state.searchHistory.unshift(data)
      // }
      // state.searchHistory.unshift(data)
      if (!state.searchHistory.includes(data)) {
        state.searchHistory.unshift(data)
      }
    }
  },
  actions: {},
  modules: {}
})
